package com.asktgapp.user.activity;

import android.app.Activity;
import android.app.KeyguardManager;
import android.app.WallpaperManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.asktgapp.R;
import com.asktgapp.hxsg.BiuEaseHelper;
import com.asktgapp.modulebase.common.util.PreferencesUtil;
import com.asktgapp.modulebase.common.util.Util;

public class MessageActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i("tag", "onCreate:启动了消息内容的activity ");
        //四个标志位顾名思义，分别是锁屏状态下显示，解锁，保持屏幕长亮，打开屏幕。这样当Activity启动的时候，它会解锁并亮屏显示。
        Window win = getWindow();
        win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED //锁屏状态下显示
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD //解锁
                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON //保持屏幕长亮
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); //打开屏幕
//        Drawable wallPaper = WallpaperManager.getInstance( this).getDrawable();
//        win.setBackgroundDrawable(wallPaper);
//        WindowManager.LayoutParams params = win.getAttributes();
//        params.x = 0;
//        params.y = 0;
//        params.height = 1;
//        params.width = 1;
//        win.setAttributes(params);
        setContentView(R.layout.activity_message);

        TextView tvContent = findViewById(R.id.tvContent);
        tvContent.setText(getIntent().getStringExtra("content"));
        ImageView ivClose = findViewById(R.id.close_iv);
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        LinearLayout layout = findViewById(R.id.message_layout);
        layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //先解锁系统自带锁屏服务，放在锁屏界面里面
                KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
                keyguardManager.newKeyguardLock("").disableKeyguard(); //解锁
//点击进入消息对应的页面
                int type = Integer.parseInt(getIntent().getStringExtra("type"));
                String ref_id = getIntent().getStringExtra("ref_id");
                String ref_type = getIntent().getStringExtra("ref_type");
                if (type == 2) {
                    Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                } else if (type == 100) {
                    Intent intent;
                    switch (ref_type) {
                        case "二手设备列表":
                            intent = new Intent(getApplicationContext(), UsedSecondhandTypeActivity.class);
//                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            break;
                        case "二手设备详情":
                            intent = new Intent(getApplicationContext(), UsedMachineDetailActivity.class);
//                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.putExtra("id", ref_id);
                            startActivity(intent);
                            break;
                        case "出租找活列表":
                            intent = new Intent(getApplicationContext(), RentMachineNewActivity.class);
//                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            break;
                        case "出租找活详情":
                            intent = new Intent(getApplicationContext(), RentDetailActivity.class);
//                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.putExtra("id", ref_id);
                            startActivity(intent);
                            break;
                        case "维修妙招列表":
                            intent = new Intent(getApplicationContext(), IndurstryInformationActivity.class);
//                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            break;
                        case "维修妙招详情":
                            intent = new Intent(getApplicationContext(), IndustryInfoDetailActivity.class);
//                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.putExtra("id", ref_id);
                            startActivity(intent);
                            break;
                        case "上门服务列表":
                            intent = new Intent(getApplicationContext(), HomeServiceActivity.class);
//                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            break;
                        case "上门服务详情":
                            intent = new Intent(getApplicationContext(), HomeServiceDetailActivity.class);
//                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.putExtra("id", ref_id);
                            startActivity(intent);
                            break;
                        case "工程师列表":
                            intent = new Intent(getApplicationContext(), EngineerListActivity.class);
//                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            break;
                        case "工程师详情":
                            intent = new Intent(getApplicationContext(), EngineerDetailActivity.class);
//                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.putExtra("id", ref_id);
                            startActivity(intent);
                            break;
                        case "商城列表":
                            NewWebActivity.start(getApplicationContext(), "http://shop.jg969.com:90/client/index", "找配件", 1);
                            break;
                        case "商城详情":
                            NewWebActivity.start(getApplicationContext(), ref_id, "商品详情", 0);//fengyi // bean.getShopDetailUrl()

                            break;
                    }

                }  else {
                    if (type == 7 && Util.isEmpty(ref_id)) {
                        Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);
                    } else {

                        switch (ref_type) {
                            //二手机
                            case "0":
                                Intent intent0 = new Intent(getApplicationContext(), UsedMachineDetailActivity.class);
                                intent0.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent0.putExtra("id", ref_id);
                                startActivity(intent0);
                                break;
                            //设备出租
                            case "1":
                                Intent intent1 = new Intent(getApplicationContext(), RentDetailActivity.class);
                                intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent1.putExtra("id", ref_id);
                                startActivity(intent1);
                                break;
                            //设备求租
                            case "2":
                                Intent intent2 = new Intent(getApplicationContext(), QiuZuDetailActivity.class);
                                intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent2.putExtra("id", ref_id);
                                startActivity(intent2);
                                break;
                            //问答
                            case "3":
                                FreeAskAnswerDetailActivity.startFreeAskAnswerDetailActivty( ref_id,MessageActivity.this);
                                break;
                            case "4":
                                startActivity(new Intent(getBaseContext(), MainActivity.class));
                                break;
                            case "5":
                                Intent intent5 = new Intent(getApplicationContext(), SystemPushActivity.class);
                                intent5.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent5.putExtra("type", 1);
                                intent5.putExtra("id", ref_id);
                                startActivity(intent5);

                                break;
                            case "6":
                                Intent intent6 = new Intent(getApplicationContext(), SystemMessageActivity.class);
                                intent6.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent6.putExtra("type", 1);
                                intent6.putExtra("id", ref_id);
                                startActivity(intent6);
                                break;
                        }
                    }
                }
                    finish();
                }
            });
        }
    }
